<?php
/**
 * 信息处理
 */
include("config.php");

if($conn){
    switch ($_GET['action']){
        case 'add':
            $name=$_POST['name'];
            $sex=$_POST['sex'];
            $age=$_POST['age'];
            $class=$_POST['class'];
            $sql="insert into stu(`name`,`sex`,`age`,`class`) values('$name','$sex','$age','$class')";
            $res=mysqli_query($conn,$sql);
            if($res){
                echo "<script>alert('添加成功');window.location.href='info.php';</script>";
            }else{
                echo "<script>alert('添加失败');window.location.href='add.php';</script>";
            }
            //header('Location:index.php');
            break;
        case 'edit':
            $id=$_POST['id'];
            $name=$_POST['name'];
            $sex=$_POST['sex'];
            $age=$_POST['age'];
            $class=$_POST['class'];
            $sql="update stu set name = '$name',sex='$sex',age='$age',class='$class' where id='$id'";
            $res=mysqli_query($conn,$sql);
            if($res){
                echo "<script>alert('修改成功');window.location.href='info.php';</script>";
            }else{
                echo "<script>alert('修改失败');window.location.href='info.php';</script>";
            }
        case 'del':
            $id=$_GET['id'];
            $sql="delete from stu where ID='$id'";
            $res=mysqli_query($conn,$sql);
            if($res){
                echo "<script>alert('删除成功');window.location.href='info.php';</script>";
            }else{
                echo "<script>alert('删除失败');window.location.href='info.php';</script>";
            }
    }
}